package com.ta.stage.controller;

import com.ta.stage.dao.UserRoleDao;
import com.ta.stage.entity.User;
import com.ta.stage.entity.UserRole;
import com.ta.stage.result.Result;
import com.ta.stage.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userrole/")
@Api(tags={"用户角色 UserRoleController"})
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;

    @ApiOperation(value = "查询用户角色")
    @RequestMapping(value = "findUserRole",method = RequestMethod.GET)
    @ResponseBody
    public Result findUserRole(){
        List<UserRole> userRoleList = userRoleService.list(null);
        return Result.ok(userRoleList);
    }

    @ApiOperation(value = "根据id查询用户角色")
    @GetMapping("getUserRole/{id}")
    public Result getUserRole(@PathVariable Long id){
        UserRole userRole = userRoleService.getById(id);
        return Result.ok(userRole);
    }

    @ApiOperation(value = "新增用户角色")
    @RequestMapping(value = "saveUserRole",method = RequestMethod.POST)
    @ResponseBody
    public Result saveUserRole(@RequestBody UserRole userRole){
        boolean save = userRoleService.save(userRole);
        return save?Result.ok():Result.fail();
    }

    @ApiOperation(value = "修改用户角色")
    @PostMapping("updateUserRole")
    public Result updateUserRole(@RequestBody UserRole userRole){
        boolean flag = userRoleService.updateById(userRole);
        return flag?Result.ok():Result.fail();
    }

    @ApiOperation(value = "批量删除用户角色")
    @DeleteMapping("batchRemoveUserRole")
    public Result batchRemoveUserRole(@RequestBody List<Long> idList){
        userRoleService.removeByIds(idList);
        return Result.ok();
    }
}

